﻿-var entity = ViewData["entity"] as Person
-var roles = ViewData["roles"] as List<Role>
-bool popup = ViewData.ContainsKey("popup")
-bool create = (entity.Id == 0)
-bool readOnly = ViewData.ContainsKey("readonly")
-bool isexternal = ViewData.ContainsKey("isexternal")
-bool regdata = ViewData.ContainsKey("regdata")
-bool edit = ViewData.ContainsKey("edit")
-string queryParams = ViewData.ContainsKey("queryParams") ? ViewData["queryParams"] as string : ""

%form.validate{action="person.ivp/save" + ((edit) ? "?edit=true" : ""),method="post",enctype="multipart/form-data"}
  _formfields
  =HTMLHelper.HiddenInput("id",entity.Id)
  %input#returntoopeneraftersave{type="hidden",name="returntoopeneraftersave",value=(ViewData.ContainsKey("returnToOpenerAfterSave")) ? "true" : ""}
  %input#edit{type="hidden",name="edit",value=edit ? "true" : ""}
  #content{class=(popup || isexternal?"popup":"")}
    .formheader
      %h1
        %table{width="100%"}
          %tr
            %td{width="70%"}  
              %img.icon24{src="img/headericons/user.gif"}
                -if (regdata)
                  Регистрационные данные
                -else
                  =String.Format("{0} (физическое лицо)",((create)?"Новый клиент":entity.FIO))
            %td{width="30%"}
              -if(create && popup)
                %a.floatright{href=String.Format("company.ivp/create{0}",queryParams)} Создать юридическое лицо
              -else
                %a.floatright{href=String.Format("person.ivp/union/{0}", entity.Id), style="font-size: 12px;"} Редактор объединения
    _error
    #tabs
      %ul
        %li
          %a#ageneral.selected{href="#",onclick="return setTab('general')"} Общие
        -if(!create && !isexternal && !regdata && !popup)
          %li
            %a#aorders{href="#",onclick="return setTab('orders')"} Заявки
          %li
            %a#atasks{href="#",onclick="return setTab('tasks')"} Запись на прием
          %li
            %a#acompanies{href="#",onclick="return setTab('companies')"} Юридические лица
    .formbody
      .tab#general
        .field
          %table{width="700"}
            %tr
              %td{width="220"}            
                .field
                  %label.required{for="lastname"} Фамилия
                  %input#lastname.px215.big.basictext.required{name="lastname",value=HTMLHelper.EscapeQuotes((create && ViewData.ContainsKey("lastname")) ? ViewData["lastname"] as string: entity.LastName),maxlength="100"}
              %td{width="220"} 
                .field
                  %label.required{for="name"} Имя
                  %input#name.px215.big.basictext.required{name="name",value=HTMLHelper.EscapeQuotes((create && ViewData.ContainsKey("name")) ? ViewData["name"] as string: entity.Name),maxlength="100"}
              %td{width="220"} 
                .field
                  %label{for="patronymicname"} Отчество
                  %input#patronymicname.px215.big.basictext{name="patronymicname",value=HTMLHelper.EscapeQuotes((create && ViewData.ContainsKey("patronymicname")) ? ViewData["patronymicname"] as string: entity.PatronymicName),maxlength="100"}
        .field
        %table{width="700"}
          %tr
            %td{width="220"}
              .field
                %label{for="passportserial"} Серия паспорта
                %input#passportserial.px215.digits{name="passportserial",value=entity.PassportSerial,maxlength="50"}
            %td{width="220"}
              .field
                %label{for="passportnumber"} Номер паспорта
                %input#passportnumber.px215.digits{name="passportnumber",value=entity.PassportNumber,maxlength="50"}
            %td{width="220"}
              .field
                %label{for="passportdate"} Дата выдачи паспорта
                %input#passportdate.px150.dateRU{name="passportdate",value=entity.PassportDate.ToDateString()}       
        .field
          %label{for="passportdetails"} Кем выдан паспорт
          %textarea#passportdetails.px450.basictext{name="passportdetails",rows="3",maxlength="300"}=entity.PassportDetails
        _attachedfiles
        .field
          %label{for="comment"} Комментарии
          %textarea#comment.px450.basictext{name="comment",rows="3",maxlength="300"}=entity.Comment
        .field
          %table{width="450"}
            %tr
              %td{width="210"}
                .field
                  %label{for="email"} Email
                  %input#email.px200.email{name="email",value=entity.Email,maxlength="100"}
              %td{width="210"}
                .field
                  %label.paddedleft20.required{for="phone"} Телефон
                  %table{width="200"}
                    %tr
                      %td{width="10", align="center" }
                        %label.paddedtop2 +7
                      %td{width="5", align="center" }
                        %label.paddedtop2(
                      %td{width="45", align="center" }
                        %input#phone1.px40.required.digits{name="phone1",value=create ? "" : entity.PhonePartsArray[0], minlength="3", maxlength="3", onkeyup="switchTelephoneInput(1);"}
                      %td{width="15", align="center" }
                        %label.paddedtop2)
                      %td{width="45", align="center" }
                        %input#phone2.px40.required.digits{name="phone2",value=create ? "" : entity.PhonePartsArray[1], minlength="3",maxlength="3", onkeyup="switchTelephoneInput(2);"}
                      %td{width="8", align="center" }
                        =(char)45
                      %td{width="45", align="center" }
                        %input#phone3.px40.required.digits{name="phone3",value=create ? "" : entity.PhonePartsArray[2], minlength="2",maxlength="2", onkeyup="switchTelephoneInput(3);"}
                      %td{width="8", align="center" }
                        =(char)45
                      %td{width="45", align="center" }
                        %input#phone4.px40.required.digits{name="phone4",value=create ? "" : entity.PhonePartsArray[3], minlength="2",maxlength="2"}
                    %tr
                      %td{width="10", align="center" }
                      %td{width="5", align="center" }
                      %td{width="45", align="center" }
                        %label 495
                      %td{width="15", align="center" }
                      %td{width="45", align="center" }
                        %label 791
                      %td{width="8", align="center" }
                      %td{width="45", align="center" }
                        %label 45
                      %td{width="8", align="center" }
                      %td{width="45", align="center" }
                        %label 15
        -if(!popup)
          .field.paddedbottom10
            %label{for="password"} Пароль
            -if( !create )
              #pwdplaceholder
                %a{href="#",onclick="javascript:$('#pwdplaceholder').hide();$('#newpwd').show();$('#password').attr('disabled',false); return false;"} Изменить
              #newpwd.hidden
                %input#password.px200.big.required.login{name="password",disabled="true",maxlength="50"}
            -else
              %input#password.px200.big.login{name="password",maxlength="50"}  
        -if(!popup)
          %div{class=(regdata) ? "field hidden" : "field"}
            %label.radio{for="isactivated"}
              =HTMLHelper.Checkbox("isactivated","True","", entity.IsActivated)
              ="Активирован"
          %div{class=(regdata) ? "field hidden " : "field"}
            %label.radio{for="isarchive"}
              =HTMLHelper.Checkbox("isarchive","True","", entity.IsArchive)
              ="Архивный"
            .details Архивный пользователь не может работать с системой и не может быть использован при создании новых заявок.
          %div{class=(regdata) ? "field hidden " : "field"}
            %label.radio{for="isnotify"}
              =HTMLHelper.Checkbox("isnotify","True","", entity.IsNotify)
              ="Уведомить нотариуса о клиенте"
          %div{class=(regdata) ? "field hidden " : "field"}
            %label{for="notifycomment"}Текст уведомления
            %textarea#notifycomment.px415.basictext{name="notifycomment",rows="4",maxlength="500"}=entity.NotifyComment
        -else 
          -if(!entity.IsActivated)
            .field Пользователь не активирован  
          -if(entity.IsArchive)
            .field Пользователь в архиве
          -if(entity.IsNotify)
            .field
              =string.Format("Уведомить нотариуса о клиенте: {0}", entity.NotifyComment) 
        =HTMLHelper.HiddenInput("roleid", 2, "")
        =HTMLHelper.HiddenInput("isexternal",isexternal)
        -if (ViewData.ContainsKey("opener"))
          =HTMLHelper.HiddenInput("opener",ViewData["opener"] as string)
      .tab#orders
      .tab#tasks
      .tab#companies
    .formbottom
      -if(!readOnly)
        -if (!regdata && !edit)
          -if (!isexternal)
            %button.saveandreturn#submit{type="submit",onclick="$('#returnaftersave').val('true')"} Сохранить и вернуться
          -else
            %button.saveandreturn#submit{type="submit",onclick="$('#returntoopeneraftersave').val('true')"} Сохранить и вернуться
        %button.save#submit{type="submit",onclick="$('#returnaftersave').val('')"} Сохранить
      -if(popup || edit)
        %button.return{type="button",onclick="self.close();"} Вернуться
      -else if(isexternal)
        -if (!create && ViewData.ContainsKey("opener") && (ViewData["opener"] as string) == "order")
          %button.return{type="button",onclick=String.Format("addPersonToOrder({0})",entity.Id * 10 + 1)} Вернуться
        -else
          %button.return{type="button",onclick=String.Format("addPerson({0})",entity.Id)} Вернуться
      -else if (!regdata)
        %button.return{type="button",onclick="closeForm('client.ivp/list');"} Вернуться
        
